package com.manage.competition.service.impl;

import com.manage.competition.entity.ExaminationPaper;
import com.manage.competition.mapper.ExaminationPaperMapper;
import com.manage.competition.repository.ExaminationPaperRepository;
import com.manage.competition.service.IExaminationPaperService;
import com.manage.competition.util.CurrentUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Create with IDEA
 *
 * @Author: gitee.com/KamisamaXX
 * @Date: Create in 15:40 2019/4/2
 * @Description:
 */
@Service
public class ExaminationPaperServiceImpl implements IExaminationPaperService {
    @Autowired
    private ExaminationPaperMapper examinationPaperMapper;

    @Autowired
    private ExaminationPaperRepository examinationPaperRepository;

    @Override
    public int insert(ExaminationPaper examinationPaper) {
        examinationPaper.setUpdateUser(CurrentUserUtil.getCurrentUser().getUsername());
        examinationPaper.setCreateUser(CurrentUserUtil.getCurrentUser().getUsername());
        return examinationPaperMapper.insert(examinationPaper);
    }

    @Override
    public ExaminationPaper findById(long id) {
        return examinationPaperRepository.findById(id).orElse(null);
    }

    @Override
    public int update(ExaminationPaper paper) {
        paper.setUpdateUser(CurrentUserUtil.getCurrentUser().getUsername());
        return examinationPaperMapper.updateByPrimaryKeySelective(paper);
    }

    @Override
    public int deleteByPrimaryKey(Long examPaperId) {
        return examinationPaperMapper.deleteByPrimaryKey(examPaperId);
    }
}
